﻿using System.Security.Cryptography;
using System.Text;

namespace YXChatApiService.Utility
{
    /// <summary>
    /// 密码加密类
    /// </summary>
    public static class SHA256Helper
    {
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static string SHA256EncryptString(string pwd)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(pwd);
            byte[] hash = SHA256Managed.Create().ComputeHash(bytes);

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                builder.Append(hash[i].ToString("x2"));
            }
            return builder.ToString();
        }
    }
}